tests: Don't crash if widgets go away before clipboard
authorBenjamin Otte <otte@redhat.com>
Fri, 1 Dec 2017 05:05:07 +0000 (06:05 +0100)
committerBenjamin Otte <otte@redhat.com>
Sun, 3 Dec 2017 04:46:48 +0000 (05:46 +0100)
Don't g_signal_connect() to the clipboard without protection - the
clipboard might outlast you and still emit signals.

tests/testclipboard2.c

index abc4751a30e47557573675dd694d6ed88e185350..cd72696f204218613b9c030e91cb4af1c6ce6ef2 100644 (file)
@@ -177,7 +177,7 @@ get_formats_list (GdkClipboard *clipboard)
   sw = gtk_scrolled_window_new (NULL, NULL);
 
   list = gtk_list_box_new ();
-  g_signal_connect (clipboard, "notify::formats", G_CALLBACK (clipboard_formats_change_cb), list);
+  g_signal_connect_object (clipboard, "notify::formats", G_CALLBACK (clipboard_formats_change_cb), list, 0);
   clipboard_formats_change_cb (clipboard, NULL, list);
   gtk_container_add (GTK_CONTAINER (sw), list);
 
@@ -193,7 +193,7 @@ get_contents_widget (GdkClipboard *clipboard)
   gtk_widget_set_hexpand (stack, TRUE);
   gtk_widget_set_vexpand (stack, TRUE);
   g_signal_connect (stack, "notify::visible-child", G_CALLBACK (visible_child_changed_cb), clipboard);
-  g_signal_connect (clipboard, "changed", G_CALLBACK (clipboard_changed_cb), stack);
+  g_signal_connect_object (clipboard, "changed", G_CALLBACK (clipboard_changed_cb), stack, 0);
 
   child = get_formats_list (clipboard);
   gtk_stack_add_titled (GTK_STACK (stack), child, "info", "Info");